﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework.Content.Pipeline.Serialization.Compiler;
using SimpleGameData.GameObjects;
using SimpleGameData.Animations;
using Microsoft.Xna.Framework.Content.Pipeline;

namespace SimpleGameContentProcessors.GameObjects
{
    /// <summary>
    /// This class will be instantiated by the XNA Framework Content Pipeline
    /// to write the specified data type into binary .xnb format.
    ///
    /// This should be part of a Content Pipeline Extension Library project.
    /// </summary>
    [ContentTypeWriter]
    public class AnimatedSpriteDataWriter : ContentTypeWriter<AnimatedSpriteData>
    {
        GameObjectDataWriter gameObjectDataWriter = null;

        protected override void Initialize(ContentCompiler compiler)
        {
            gameObjectDataWriter = compiler.GetTypeWriter(typeof(GameObjectData))
                as GameObjectDataWriter;

            base.Initialize(compiler);
        }

        protected override void Write(ContentWriter output, AnimatedSpriteData value)
        {
            output.WriteRawObject<GameObjectData>(value as GameObjectData, gameObjectDataWriter);

            output.WriteObject<Dictionary<AnimationKey, Animation>>(value.Animations);
        }

        public override string GetRuntimeReader(
                TargetPlatform targetPlatform)
        {
            return typeof(AnimatedSpriteDataReader).AssemblyQualifiedName;
        }
    }
}
